﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Hanhud.Web
{
    public class CSupport
    {
        public int SupportID { get; private set; }
        public string Name { get; set; }
        public string Title { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }

        private List<CNick> _nicks = null;
        public List<CNick> Nicks
        {
            get
            {
                if (_nicks == null)
                {
                    _nicks = new List<CNick>();

                    DataTable tblNick = Data.Providers.CWebProvider.Instance.GetNicks(this.SupportID);
                    foreach (DataRow row in tblNick.Rows)
                        _nicks.Add(new CNick((int)row["NickID"], (ENickType)row["NickType"], row["NickName"].ToString()));
                }
                return _nicks;
            }
        }

        public CSupport(int supportID)
        {
            this.SupportID = supportID;
        }

        public CSupport(int supportID, string name, string title, string email, string phone)
        {
            this.SupportID = supportID;
            this.Name = name;
            this.Title = title;
            this.Email = email;
            this.Phone = phone;
        }

        public static List<CSupport> GetSupports(int departmentID)
        {
            List<CSupport> supportList = new List<CSupport>();

            System.Data.DataTable tblSupport = Data.Providers.CWebProvider.Instance.GetSupports(departmentID);
            foreach (DataRow row in tblSupport.Rows)
            {
                supportList.Add(
                    new CSupport(
                        (int)row["SupportID"],
                        row["Name"].ToString(),
                        row["Title"].ToString(),
                        row["Email"].ToString(),
                        row["Phone"].ToString())
                    );
            }

            return supportList;
        }

        public static List<CDepartment> GetDepartments()
        {
            List<CDepartment> departmentList = new List<CDepartment>();

            System.Data.DataTable tblDepartment = Data.Providers.CWebProvider.Instance.GetDepartments();
            foreach (DataRow row in tblDepartment.Rows)
            {
                departmentList.Add(
                    new CDepartment(
                        (int)row["DepartmentID"],
                        row["Title"].ToString())
                    );
            }

            return departmentList;
        }
    }
}
